package projects.ufam.nodes.messages;

import projects.defaultProject.nodes.nodeImplementations.LocalizableNode;
import sinalgo.nodes.messages.Message;
import sinalgo.runtime.Global;

public class TrackingMsg extends Message {
	static int id = 1;
	int _id = 0;
	int timestamp = 0;
	int hops;
	double distance;
	private static int sent = 0, received = 0, totalDelay = 0;

	public static void msgSent() {
		sent++;
	}

	public static void clear() {
		received = 0;
		sent = 0;
	}

	public static void msgReceived(TrackingMsg msg) {
		received++;
		totalDelay += Global.currentTime - msg.timestamp;
	}

	LocalizableNode node = null;

	public TrackingMsg(LocalizableNode node) {
		_id = id++;
		timestamp = (int) Global.currentTime;
		this.node = node;
		hops = 0;
	}

	public int hashCode() {
		return _id;
	}

	public double getDistance() {
		return distance;
	}

	public void setDistance(double distance) {
		this.distance = distance;
	}

	public int getHops() {
		return hops;
	}

	public void setHops(int hops) {
		this.hops = hops;
	}

	@Override
	public Message clone() {
		TrackingMsg m = new TrackingMsg(this.node);
		m.timestamp = timestamp;
		m._id = this._id;
		m.setDistance(this.distance);
		m.setHops(this.hops);
		return m;
	}

	public LocalizableNode getNode() {
		return node;
	}

	public void setNode(LocalizableNode node) {
		this.node = node;
	}

	@Override
	public int getMessageSize() {
		return 10;
	}

	public int getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(int timestamp) {
		this.timestamp = timestamp;
	}

	public static int getSent() {
		return sent;
	}

	public static int getReceived() {
		return received;
	}

	public static int getTotalDelay() {
		return totalDelay;
	}

	public int getId() {
		return _id;
	}
}
